using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Silverlight.Controls.ToolTips.Demo.ValueConverters
{
    public class DurationToDoubleConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var input = (Duration) value;
            return input.HasTimeSpan ? input.TimeSpan.TotalSeconds : 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var input = (double)value;
            return new Duration(TimeSpan.FromSeconds(input));
        }
    }
}